package com.myres.struts2.action;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;

import com.myres.biz.ShopBiz;
import com.myres.dao.ProductDao;
import com.myres.dao.ScoreDao;
import com.myres.dao.ShopDao;
import com.myres.dao.UserDao;
import com.myres.model.Product;
import com.myres.model.Score;
import com.myres.model.Shop;
import com.myres.model.User;
import com.myres.service.ShopService;
import com.myres.spring.SpringUtils;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AddScoreAction extends ActionSupport {
	private String result;
	private ScoreDao scoreDao; 
	private UserDao userDao;
	private String number;
	private int amount;
	private Score score;
	private int adderId;
	public int getAdderId() {
		return adderId;
	}
	public void setAdderId(int adderId) {
		this.adderId = adderId;
	}
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	public int getAmount() {
		return amount;
	}
	public void setAmount(int amount) {
		this.amount = amount;
	}
	public Score getScore() {
		return score;
	}
	public void setScore(Score score) {
		this.score = score;
	}
	public ScoreDao getScoreDao() {
		return scoreDao;
	}
	public void setScoreDao(ScoreDao scoreDao) {
		this.scoreDao = scoreDao;
	}
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public String execute() {
		User user = userDao.get(adderId);
		score.setAdder(user);
		score.setScore(amount);
		score.setNote(Score.NOTE_CASH);
		score.setReason(Score.TYPE_CASH);
		List<User> users = userDao.get(number);
		if(users == null || users.size() == 0) return SUCCESS;
		User addee = users.get(0);
		score.setUser(addee);
		
		scoreDao.insertScore(score);
		
		result="<?xml encoding=\"utf-8\" version=\"1.0\" ?>";
		result +="<s><m>"+number+"</m><n>"+addee.getName()+"</n><a>"+amount+"</a></s>";
		return SUCCESS;
	}
}